package com.service.totalauth.rabbitmq;

import com.service.config.dto.MailBean;
import com.service.config.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @ClassName: SignUserServiceTest
 * @Description:
 * @Author guochuang
 * @Date 2023/8/9
 * @Version 1.0
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class SignUserServiceTest {
    @Autowired
    private MsgProducer msgProducer;
    @Resource
    RedisUtil redisUtil;

    @Test
    public void dod() {
        MailBean mailBean = new MailBean();
        mailBean.setContent("demo");
        msgProducer.sendMsg(mailBean,2);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>");
    }
    @Test
    public void dod1() {
        ExecutorService executorService = Executors.newFixedThreadPool(20);
        for (int i=0;i<30;i++) {
            int finalI = i;
            log.info("s:{}",i);
            AtomicBoolean ex1 = new AtomicBoolean(false);
            executorService.submit(()->{
                boolean ex11 = redisUtil.setNxAndEx("ex1", String.valueOf(finalI), 1, TimeUnit.SECONDS);
                log.info("th:{},{}",ex11,finalI);
                });
        }

    }
}
